USE [Forums]
GO

/****** Object:  StoredProcedure [dbo].[SPQuestionInsert]    Script Date: 08/08/2012 15:33:37 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[SPQuestionInsert]
	@name nvarchar(50)
	,@title nvarchar(150)
	,@description nvarchar(500)
	,@forumID int
	,@userID int
AS
BEGIN TRY
	BEGIN TRANSACTION
	
	Declare @maxQID int;
	select @maxQID = max(q_id) from ASK_Question
	select @maxQID = isnull(@maxQID,0)

	set 
	@maxQID = @maxQID + 1;

	INSERT INTO ASK_Question
	(
	q_ID
	,name
	,title
	,description
	,forumID
	,viewed
	,userID
	,publishDate
	)
	VALUES
	(
	@maxQID
	,@name
	,@title
	,@description
	,@forumID
	,0
	,@userID
	,GETUTCDATE()
	)
	COMMIT

END TRY
BEGIN CATCH
	IF @@TRANCOUNT > 0
		ROLLBACK

  -- Raise an error with the details of the exception
	DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int
	SELECT @ErrMsg = ERROR_MESSAGE(),
		 @ErrSeverity = ERROR_SEVERITY()

	RAISERROR(@ErrMsg, @ErrSeverity, 1)

END CATCH
GO


